package no.weather.misc;

import no.weather.R;
import no.weather.WeatherElement;
import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ProgressListAdapter implements ListAdapter, IProgress {
	private final LayoutInflater mInflater;
	private Float progress;
	private ProgressBar mProgressBar;
	
	public ProgressListAdapter(LayoutInflater inflator) {
		super();
		mInflater = inflator;
	}
	
	@Override
	public int getCount() {
		return 1;
	}

	@Override
	public Object getItem(int position) {
		return progress;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public int getItemViewType(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.progress_list_item,
					null);
		}

		ProgressBar progressBar = (ProgressBar) convertView.findViewById(R.id.ProgressBar);
		progressBar.setProgress((int) (progress*progressBar.getMax()));
		mProgressBar = progressBar;

		return convertView;
	}

	@Override
	public int getViewTypeCount() {
		return 1;
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}

	@Override
	public boolean isEmpty() {
		return false;
	}

	@Override
	public void registerDataSetObserver(DataSetObserver observer) {
		

	}

	@Override
	public void unregisterDataSetObserver(DataSetObserver observer) {
		

	}

	@Override
	public boolean areAllItemsEnabled() {
		return false;
	}

	@Override
	public boolean isEnabled(int arg0) {
		return false;
	}

	@Override
	public void publishProgress(Float progress) {
		
		mProgressBar.setProgress((int) (progress*mProgressBar.getMax()));
		
	}

}
